﻿//////////////////////////////////////////////////////////////////////////////
//
//  Copyright © 1998-2024 Glodon Company Limited.  All rights reserved.
//
//  Use of this software is subject to the terms of the Glodon license
//  agreement provided at the time of installation or download, or which
//  otherwise accompanies this software in either electronic or hard copy form.  
//
//////////////////////////////////////////////////////////////////////////////

#pragma once
#include "GcmpDatabase.h"
namespace gcmp
{
    class IDbObject;
    class NdbObject;
    class NdbClassSchema;

    /// \brief 对外提供拷贝，合并对象能力
    class GCMP_DATABASE_EXPORT NdbObjectCopyUtils
    {
    public:
        /// \brief 拷贝IDbObject
        /// \param pDbObject 给定的IDbObject指针
        /// \return 返回pDbObject的拷贝
        static OwnerPtr<IDbObject> CopyObject(const IDbObject* pDbObject);

        /// \brief 拷贝NdbObject
        /// \param pNdbObject 给定的NdbObject指针
        /// \return 返回pNdbObject的拷贝
        static OwnerPtr<NdbObject> CopyObject(const NdbObject* pObject);

        /// \brief 在指定的地址拷贝NdbObject
        /// \param pTargetObject 拷贝到该处
        /// \param pSourceObject 源对象指针
        /// \param pClassSchema 类Schema。没有指定ClassSchema时，
        ///     认为pTargetObject和pSourceObject拥有相同的ClassSchema
        /// \return bool 发生错误时，返回false
        static bool EmplaceCopyObject(
            NdbObject * pTargetObject, 
            const NdbObject* pSourceObject, 
            const NdbClassSchema * pClassSchema = nullptr
        );
    };
}
